<?php

    namespace app\admin\controller;
    use think\Controller;
    use app\admin\model\Classes;
    use app\admin\model\Course;
    use think\Request;
    use think\Db;

    class Classesshow extends Controller{


        public function index(){
            //volist遍历数据库
            $role = New Classes();
            $data = $role -> class_list();
            //dump($data->toArray());
            $this->assign('class_list',$data);

            //新添班级里面的课程遍历volist
            $course = New Course();
            $coursendata = $course -> coursen_list();
            //dump($data->toArray());
            $this->assign('coursen_list',$coursendata);

            //修改班级里面的课程遍历volist
            $course = New Course();
            $change_coursendata = $course -> change_coursen_list();
            //dump($data->toArray());
            $this->assign('change_coursen_list',$change_coursendata);

            return $this->fetch();
        }

        public function newclass(){
            if(request()->isPost()){
                $classes=new Classes();
                $data=input('post.');
                // var_dump($data);
                $num=$classes->insert($data);
                if($num==1){
                    $this->success("新添成功","admin/classesshow/index");
                }else{
                    $this->error('新添失败');
                }
            }
            return $this->fetch();
        }

        public function classdelete(Request $Request){
            $id = request()->param();
            // var_dump($id);
            
            $res = DB::table("classes")->delete($id);
            if($res){
                $this->success("OK","admin/classesshow/index");
            }else{
                $this->error();
            }
        }

        public function changeclass(){

            if(request()->isPost()){
                $classes=new Classes();
                $data=input('post.');
                // var_dump($data);
                $num=$classes->change($data);
                
                if($num==1){
                    $this->success("修改成功","admin/classesshow/index");
                }else{
                    $this->error('修改失败');
                }
            }
        }

        

    }

?>